#1. 确定CMake的最低版本需求
CMAKE_MINIMUM_REQUIRED(VERSION 3.0.0)

#2. 确定工程名
PROJECT(WtUftRunner LANGUAGES CXX)
SET(CMAKE_CXX_STANDARD 17)

set(OUTPUT_BIN ${CMAKE_BINARY_DIR}/build_${PLATFORM}/${CMAKE_BUILD_TYPE}/bin)
SET(EXECUTABLE_OUTPUT_PATH ${OUTPUT_BIN}/WtUftRunner)

#7. 添加源码
file(GLOB SRCS *.cpp)
file(GLOB HDRS *.h)

INCLUDE_DIRECTORIES(${INCS})
LINK_DIRECTORIES(${LNKS})

SET(LIBS
	WtUftCore
	WTSTools
    WTSUtils
    WtShareHelper
	)

LIST(APPEND LIBS
	dl
	pthread
	boost_filesystem
	boost_thread)

ADD_EXECUTABLE(WtUftRunner ${SRCS} ${HDRS})
TARGET_LINK_LIBRARIES(WtUftRunner ${LIBS})

IF (MSVC)
ELSE (GNUCC)
	SET_TARGET_PROPERTIES(WtUftRunner PROPERTIES
        LINK_FLAGS_RELEASE -s)
ENDIF ()

file(MAKE_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}/parsers/)
file(MAKE_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}/traders/)
file(MAKE_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}/uft/)

set(CTPDIR ${CMAKE_SOURCE_DIR}/API/CTP6.3.15)
set(CTPMINIDIR ${CMAKE_SOURCE_DIR}/API/CTPMini1.5.8)

add_custom_command(TARGET WtUftRunner POST_BUILD
	COMMAND ${CMAKE_COMMAND} -E
	copy ${CMAKE_BINARY_DIR}/build_${PLATFORM}/${CMAKE_BUILD_TYPE}/bin/${PREFIX}TraderCTP${SUFFIX} ${EXECUTABLE_OUTPUT_PATH}/traders/

    COMMAND ${CMAKE_COMMAND} -E
	copy ${CMAKE_BINARY_DIR}/build_${PLATFORM}/${CMAKE_BUILD_TYPE}/bin/${PREFIX}ParserCTP${SUFFIX} ${EXECUTABLE_OUTPUT_PATH}/parsers/

	COMMAND ${CMAKE_COMMAND} -E
	copy ${CTPDIR}/linux/thosttraderapi_se.so ${EXECUTABLE_OUTPUT_PATH}/traders/

    COMMAND ${CMAKE_COMMAND} -E
	copy ${CTPDIR}/linux/thostmduserapi_se.so ${EXECUTABLE_OUTPUT_PATH}/parsers/

	COMMAND ${CMAKE_COMMAND} -E
	copy ${CTPMINIDIR}/linux/libthosttraderapi.so ${EXECUTABLE_OUTPUT_PATH}/traders/

    COMMAND ${CMAKE_COMMAND} -E
	copy ${CTPMINIDIR}/linux/libthostmduserapi.so ${EXECUTABLE_OUTPUT_PATH}/parsers/

    COMMAND ${CMAKE_COMMAND} -E
	copy_directory ${OUTPUT_BIN}/WtUftRunner ${CMAKE_SOURCE_DIR}/../dist/WtUftRunner

	COMMENT "depends modules copied")


